package objects;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class UserSet{
	
	private String name = "UserSet";
	private Set<User> storedUsers = null;
	
	public UserSet(Set<User> users) {
		storedUsers = new HashSet<User>(users);
	}

	public UserSet(List<User> users) {
		storedUsers = new HashSet<User>(users);
	}
	
	public UserSet() {
		storedUsers = new HashSet<User>();
	}

	public Set<User> getStoredUsers() {
		return storedUsers;
	}
	
	public UserSet withAdded(User user) {
		UserSet user2 = new UserSet(storedUsers);
		user2.storedUsers.add(user);
		return user2;
	}

	
	public UserSet without(User user) {
		UserSet userSet2 = new UserSet(storedUsers);
		userSet2.storedUsers.remove(user);
		return userSet2;
	}
	
	public int size() {
		return storedUsers.size();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((storedUsers == null) ? 0 : storedUsers.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserSet other = (UserSet) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (storedUsers == null) {
			if (other.storedUsers != null)
				return false;
		} else if (!storedUsers.equals(other.storedUsers))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "UserSet [name=" + name + ", storedUsers=" + storedUsers + "]";
	}

	
	

}
